package cn.sc.allinpay.allfavour.business.ewallet;

import android.os.Bundle;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.View;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.CashierInputFilter;


/**
 * activity 电子钱包
 * author：pany
 * on 2017/12/1 11:14
 */
public class EWalletActivity extends BaseActivity<EWalletContract.View, EWalletContract.Presenter>
        implements EWalletContract.View {

    @BindView(R.id.tvTransAmt)
    AppCompatTextView tvTransAmt;//交易金额
    @BindView(R.id.tvPaidAmt)
    AppCompatTextView tvPaidAmt;//剩余金额

    @BindView(R.id.tvMemberLevel)
    AppCompatTextView tvMemberLevel;//等级
    @BindView(R.id.tvMemberName)
    AppCompatTextView tvMemberName;//会员名称
    @BindView(R.id.tvMemberNo)
    AppCompatTextView tvMemberNo;//会员号

    @BindView(R.id.tvEWalletBal)
    AppCompatTextView tvEWalletBal;//电子钱包余额
    @BindView(R.id.etEWalletAmt)
    AppCompatEditText etEWalletAmt;//电子钱包消费金额

    @Override
    protected int layoutId() {
        return R.layout.activity_ewallet;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("电子钱包");
    }

    @Override
    protected EWalletContract.Presenter bindPresenter() {
        return new EWalletPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {

    }

    @Override
    public void showTransAmt(String amt) {
        tvTransAmt.setText(amt);
    }

    @Override
    public void showPaidAmt(String data) {
        tvPaidAmt.setText(data);
    }

    @Override
    public void showMemberLevel(String data) {
        tvMemberLevel.setText(data);
    }

    @Override
    public void showMemberName(String data) {
        tvMemberName.setText(data);
    }

    @Override
    public void showMemberNo(String data) {
        tvMemberNo.setText(data);
    }

    @Override
    public void setEWalletMaxAmt(String maxAmt) {
        //设置输入的最大金额
        InputFilter[] filters = {new CashierInputFilter(maxAmt)};
        etEWalletAmt.setFilters(filters);
        etEWalletAmt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                etEWalletAmt.setSelection(editable.length());
                presenter.calculateAmt();
            }
        });
    }

    @Override
    public void showEWalletBal(String data) {
        tvEWalletBal.setText(data);
    }

    @Override
    public void showEWalletAmt(String data) {
        etEWalletAmt.setText(data);
    }

    @Override
    public String getEWalletAmt() {
        return etEWalletAmt.getText().toString();
    }


    @OnClick(R.id.btnConfirm)
    public void clickConfirm() {
        presenter.setActivityForResult();
    }
}
